<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/17/017
 * Time: 19:18
 */

namespace app\api\model;

use think\Model;


class SearchWord extends ApiModel
{

    //前置条件
    protected function base($query)
    {

    }

    //新增关键词
    public function addWord($word)
    {
        $user_id = input('id');
        if($this->where(['user_id' => $user_id,'word' => $word])->find()){//如果存在关键字,就返回
            return;
        }
        $this->user_id = $user_id;
        $this->word = $word;
        $this->createtime = time();
        $this->save();
    }

    //获取指定用户搜索过的关键字
    public static function getList($id)
    {
        $res['data'] = self::field('id','word')
            ->where('user_id',$id)
            ->order('createtime desc')
            ->limit(6)
            ->select();
        return $res;
    }

}